{include file="index/header" /}
<link rel="stylesheet" type="text/css" href="__PUBLIC__css/jedate.css">
<script type="text/javascript" src="__PUBLIC__js/jquery.jedate.min.js"></script>
<style type="text/css">
	._blank{margin-left: 10px;}
</style>
<body>
	<div class="panel admin-panel">
		<form method="post" action="" id="listform">
			<div class="panel-head"><strong class="icon-reorder"> {$title}</strong></div>
			<div class="padding border-bottom">
				<ul class="search" style="padding-left:10px;">
					{if $admin['role_id'] neq 8}<li> <a class="button border-main icon-plus-square-o" href="{:url('studentadd',['class_id'=>$class_id])}"> 添加内容</a> </li>{/if}
					<li>搜索：</li>
					<li>
						<input type="search" placeholder="手机号/邮箱/昵称" name="phone" value="{$phone}" class="input"  style="width:250px; line-height:17px;display:inline-block;"/>
						<a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a>
					</li>
					<li>
						<a href="{:url('studentstatus',['id'=>$class_id])}" class="button border-main icon-download" > 导出本月数据</a>
					</li>
				</ul>
			</div>
			<table class="table table-hover text-center" style="padding-left: 20px;">
				<tr><td colspan="9" align="left" style="margin-left:40px;font-size: 15px;">总人数：{$data|count=###};<span class="_blank"></span> 总时长：<span class="sum">0</span><span class="_blank"></span> （ 当天<span class="already">0</span>人学过 | <span class="nostudy">0</span>人没学）<input type="button" value="获取状态" onclick="getsum(this)" /></td></tr>
				<tr>
					<th style="text-align:left;">序号</th>
					<th style="cursor:help;text-align:left;" title="点击对应昵称修改">备注</th>
					<th style="cursor:help;text-align:left;">昵称</th>
					<th style="text-align:left;">信息</th>
					<th style="text-align:left;">学习状况</th>
					{if $admin['role_id'] neq 8}<th style="text-align:left;">入班申请</th>{/if}
				</tr>
				{foreach $data as $k=>$v}
				<tr>
					<td align="left">{$k+1}</td>
					<td  align="left" style="cursor:pointer;"><span class='remark' data-id={$v.know_user_id}>{if $v.know_remarks}{$v.know_remarks}{else}<font color="#ddd">点击修改</font>{/if}</span></td>
					<td  align="left" style="cursor:pointer;">{$v.know_nickname}</td>
					<td align="left">{if $v.know_phone}{$v.know_phone}{else}{$v.know_email}{/if}<br/>{$v.type}<br>{$v.state}</td>
					<td align="left" id="status{$v.know_user_id}" class="status"></td>
					{if $admin['role_id'] neq 8}<td align="left"><div class="button-group">
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('record',['id'=>$v['know_user_id']])}"><span class="icon-edit"></span> 学习记录</a> 
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('student_training',['id'=>$v['know_user_id']])}"><span class="icon-edit"></span> 实操</a> 
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('student_question',['id'=>$v['know_user_id']])}"><span class="icon-edit"></span> 问答</a> <br/>
						{switch name="$v.status" }
						{case value="none"}
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('join',['status'=>'passed','user_id' => $v['know_user_id'],'class_id'=>$class_id,'phone'=>$phone])}"><span class="icon-edit"></span> 同意入班</a> 
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('join',['status'=>'unpassed','user_id' => $v['know_user_id'],'class_id'=>$class_id,'phone'=>$phone])}"><span class="icon-edit"></span> 拒绝入班</a>{/case}
						{case value="passed"}
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('join',['status'=>'unpassed','user_id' => $v['know_user_id'],'class_id'=>$class_id,'phone'=>$phone])}"><span class="icon-edit"></span> 拒绝入班</a>{/case}
						{case value="unpassed"}
						<a class="button border-main" style="padding: 10px 5px;" href="{:url('join',['status'=>'passed','user_id' => $v['know_user_id'],'class_id'=>$class_id,'phone'=>$phone])}"><span class="icon-edit"></span> 同意入班</a> {/case}{/switch}
						<a class="button border-red" onclick="if(confirm('确定移出?')==false)return false;" style="padding: 10px 5px;" href="{:url('moveout',['user_id' => $v['know_user_id'],'class_id'=>$class_id,'phone'=>$phone])}"><span class="icon-edit"></span> 移出班级</a>
					</div></td>{/if}
				</tr>
				{/foreach}
			</table>
		</form>
	</div>
	<script>
		function changesearch(){
			$("#listform").submit();
		}
		$(document).on('click','.remark',function(){
			var content = $(this).text();
			if(content == '点击修改') content = '';
			$(this).parent().html('<input type="text" placeholder="昵称" name="nickname" value="'+content+'" class="input fo" data-id="'+$(this).data('id')+'"/>');
		});
		$(document).on('blur','.fo',function(){
			var _ts = $(this);
			if(_ts.val() == '') {
				alert('不能为空');return;
			}
			$.ajax({
				data:{id:_ts.data('id'),remarks:_ts.val()},
				url:"/mine/remarks",
				type:'post',
				success:function(obj){
					_ts.parent().html('<span class="remark" data-id="'+_ts.data('id')+'">'+_ts.val()+'</span>');
				}
			})
		});
		function getsum(ts){
			$(ts).attr('disabled','disabled');
			$(ts).val('获取中');
			var userIds = [];
			$(".remark").each(function(){
				userIds.push($(this).data('id'));
			});
			$.ajax({
				data:{user_id:userIds,class_id:"{$class_id}"},
				url:"{:url('getusersum')}",
				type:'post',
				success:function(obj){
					$('.sum').text(obj.sum);
					$('.already').text(obj.already);
					$('.nostudy').text(obj.nostudy);
					$.each(obj.data,function(i,val){
						$('#status'+i).append('<table class="table table-hover text-center"><tr>');
						$.each(val,function(i1,val1){
							$('#status'+i).append('<th>'+i1+'</th>');
						});
						$('#status'+i).append('</tr><tr>');
						$.each(val,function(i1,val1){
							$('#status'+i).append('<td>'+val1+'</td>');
						});
						$('#status'+i).append('</tr></table>');
					});
					$.each($('.status'),function(i,val){
						if($(this).html() == '') $(this).html('无记录');
					});
					$(ts).val('获取成功');
				}
			})
		}
	</script>
</body></html>